<!DOCTYPE html>
<html lang="zh" xmlns:th="http://www.thymeleaf.org" >
<head>
	<th:block th:include="include :: header('新增申请内容')" />
</head>
<body class="white-bg">
	<div class="wrapper wrapper-content animated fadeInRight ibox-content">
		<form class="form-horizontal m" id="form-content-add">
			<div class="form-group">
				<label class="col-sm-3 control-label">申请类型：</label>
				<div class="col-sm-8">
					<select id="appType" name="typeId" class="form-control select2-multiple" >
						<option th:each="appType,i:${appTypes}" th:value="${appType.typeId}" th:text="${appType.typeName}" th:selected="${i==0}" ></option>
					</select>

				</div>
			</div>

			<div class="form-group">
				<label class="col-sm-3 control-label">申请内容描述：</label>
				<div class="col-sm-8">
					<input id="remark" name="remark" class="form-control"></input>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">申请内容：</label>
				<div class="col-sm-8">
					<textarea id="contentText" name="contentText" class="form-control"></textarea>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">申请人工号：</label>
				<div class="col-sm-8">
					<input id="empId" name="empId" class="form-control"></input>
				</div>
			</div>
			<div class="form-group">
				<label class="col-sm-3 control-label">申请人：</label>
				<div class="col-sm-8">
					<input id="empName" name="empName" class="form-control" readonly="readonly"></input>
				</div>
			</div>
		</form>
	</div>
	<th:block th:include="include :: footer" />
	<script type="text/javascript">
		var prefix = ctx + "per/app/content";
	    
		$("#form-content-add").validate({
			onkeyup: false,
			rules:{
				empId:{
					remote: {
		                url: prefix + "/checkEmpId",
		                type: "post",
		                dataType: "json",
		                data: {
		                	"empId" : function() {
		                        return $.common.trim($("#empId").val());
		                    }
		                },
		                dataFilter: function(data, type) {


							if (data.search("没有该员工")!=-1){
								return false

							}

							return true;


		                }
		            }
				},
			},
			messages: {
				"empId": {
					remote: "没有该员工"
				},

				"empName": {
					required: "申请人名字为空"
				}
			},
		    focusCleanup: true
		});
		
		function submitHandler() {
	        if ($.validate.form()) {
	        	$.operate.save(prefix + "/add", $('#form-content-add').serialize());
	        }
	    }
	    $(function () {
			$("#empId").blur(function () {
			var empId=$("#empId").val();
			$.ajax({
				url: prefix + "/checkEmpId",
				type: "post",
				dataType: "json",
				async:false,
				data: {
					empId:empId
				},
				success:function (data) {

                   if (data.remark=="没有该员工"){
					   $("#empName").val("")
				   }
					$("#empName").val(data.empName)
				},
				error:function () {

				}
			})

			})

		})

	</script>
</body>
</html>
